package by.bsu.android.lab.menu.sub;

public class SubMenuActivity extends Activity {
    public static final byte IDM_OPEN = 1001;
    public static final byte IDM_SAVE = 1002;
    public static final byte IDM_NEW = 1003;
    public static final byte IDM_CUT = 1004;
    public static final byte IDM_COPY = 1005;
    public static final byte IDM_PASTE = 1006;
    public static final byte IDM_HELP = 1007;

    public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.main);
    }

    public boolean onCreateOptionsMenu(Menu menu) {

	SubMenu subMenuFile = menu.addSubMenu("File");
	subMenuFile.add(Menu.NONE, IDM_NEW, Menu.NONE, "New");
	subMenuFile.add(Menu.NONE, IDM_OPEN, Menu.NONE, "Open");
	subMenuFile.add(Menu.NONE, IDM_SAVE, Menu.NONE, "Save");

	SubMenu subMenuEdit = menu.addSubMenu("Edit");
	subMenuEdit.add(Menu.NONE, IDM_CUT, Menu.NONE, "Cut");
	subMenuEdit.add(Menu.NONE, IDM_COPY, Menu.NONE, "Copy");
	subMenuEdit.add(Menu.NONE, IDM_PASTE, Menu.NONE, "Paste");

	menu.add(Menu.NONE, IDM_HELP, Menu.NONE, "Help");

	return (super.onCreateOptionsMenu(menu));

    }

    public boolean onOptionsItemSelected(MenuItem item) {

	String message;
	switch (item.getItemId()) {
	case IDM_NEW:
	    message = "New item selected";
	    break;
	case IDM_OPEN:
	    message = "Open item selected";
	    break;
	case IDM_SAVE:
	    message = "Save item selected";
	    break;
	case IDM_CUT:
	    message = "Cut item selected";
	    break;
	case IDM_COPY:
	    message = "Copy item selected";
	    break;
	case IDM_HELP:
	    message = "Help item selected";
	    break;
	default:
	    return false;

	}
	Toast toast = Toast.makeText(this, message, Toast.LENGTH_SHORT);
	toast.setGravity(Gravity.CENTER, 0, 0);
	toast.show();
	return true;

    }
}